package com.ruicar.afs.cloud.apply.applytocontract;

import com.ruicar.afs.cloud.apply.common.utils.ApplyConfig;
import com.ruicar.afs.cloud.basic.outer.api.common.dto.BasicCancelInfoConditionDto;
import com.ruicar.afs.cloud.basic.outer.api.common.feign.CommonFeign;
import com.ruicar.afs.cloud.basic.outer.api.common.gateway.ContractToApplyGateWay;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.modules.contract.enums.ContractFeginParamEnum;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author xudongdong
 * @date 2020-06-16
 */
@Slf4j
@RestController
@AllArgsConstructor
public class BasicContractCommonController {

    private final ContractToApplyGateWay contractToApplyGateWay;

    private final CommonFeign commonFeign;

    private final ApplyConfig applyConfig;

    @ApiOperation(value = "根据合同号码查询资产信息")
    @PostMapping("contractGateway/getCarDetailInfo")
    public IResponse getCustAssetInfo(@RequestParam("contractNo") String contractNo) {
        return contractToApplyGateWay.getCarDetailInfo(contractNo, heards());
    }

    @ApiOperation(value = "根据合同号码查询合同信息")
    @PostMapping("/contractGateway/getContractDetailInfo")
    public IResponse findByContractNo(@RequestParam("contractNo") String contractNo) {
        return contractToApplyGateWay.getContractDetailInfo(contractNo, heards());
    }

    @ApiOperation(value = "根据合同号码和角色类型查询客户信息")
    @PostMapping("contractGateway/getCustInfo")
    public IResponse getCustInfo(@RequestParam("contractNo") String contractNo) {
        return contractToApplyGateWay.getCustInfo(contractNo, heards());
    }

    @ApiOperation(value = "根绝合同号码查询还款计划表列表信息")
    @PostMapping("contractGateway/getRepaymentPlanInfoList")
    public IResponse findFinanceInfo(@RequestParam("contractNo") String contractNo) {
        return contractToApplyGateWay.getRepaymentPlanInfoList(contractNo, heards());
    }

    @ApiOperation(value = "根据合同号码查询挂靠信息")
    @PostMapping("custAnchorInfo/getCustAnchorInfo")
    public IResponse getCustAnchorInfo(@RequestParam("contractNo") String contractNo) {
        return commonFeign.getCustAnchorInfo(contractNo, heards());
    }

    @PostMapping("contractGateway/getCustInfoList")
    @ApiOperation(value = "根据合同号码查询客户信息列表")
    public IResponse getInsurancePopList(@RequestParam("contractNo") String contractNo) {
        return contractToApplyGateWay.getCustInfoList(contractNo, heards());
    }

    @ApiOperation(value = "根据合同号码查询保险信息")
    @PostMapping("custInsuranceInfo/getCustInsuranceInfo")
    public IResponse getCustInsuranceInfo(@RequestParam("contractNo") String contractNo) {
        return commonFeign.getCustInsuranceInfo(contractNo, heards());
    }

    @ApiOperation(value = "新增申请弹框页面统一数据查询接口")
    @PostMapping("contractGateway/getContractInfoList")
    public IResponse getAlertTableData(@RequestBody BasicCancelInfoConditionDto condition) {
        return contractToApplyGateWay.getContractInfoList(condition, heards());
    }


    private Map heards() {
        Map<String, String> heards = new HashMap<>(16);
        heards.put(AfsEnumUtil.key(ContractFeginParamEnum.BASIC_CLIENT_ID), applyConfig.getContractClientId());
        heards.put(AfsEnumUtil.key(ContractFeginParamEnum.BASIC_CLIENT_SECRET), applyConfig.getContractClientSecret());
        return heards;
    }
}
